package main

import (
	"flag"
	"fmt"
	"order/model"

	"order/internal/config"
	"order/internal/server"
	"order/internal/svc"
	"order/order"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"

	_ "order/model"
)

var configFile = flag.String("f", "etc/order.yaml", "the config file")

func main() {
	flag.Parse()

	//var c config.Config
	conf.MustLoad(*configFile, &config.ConfigInfo)
	model.InitDb()
	ctx := svc.NewServiceContext(config.ConfigInfo)

	s := zrpc.MustNewServer(config.ConfigInfo.RpcServerConf, func(grpcServer *grpc.Server) {
		order.RegisterOrderServer(grpcServer, server.NewOrderServer(ctx))

		reflection.Register(grpcServer)
	})
	defer s.Stop()

	fmt.Printf("Starting rpc server at %s...\n", config.ConfigInfo.ListenOn)
	s.Start()
}
